<!DOCTYPE html>
<html lang="en" xmlns:v-model="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <script src="../../js/jpuery/jquery.js"></script>
    <script src="../../js/vue/vue.js"></script>
</head>
<body>
<div id="app">
    <form id="editFrom">
        <input type="hidden" name="id" v-model:value="emp.id">
        用户名：<input name="name" v-model:value="emp.name"><br/>
        年  龄：<input name="age" v-model:value="emp.age"><br/>
        <input type="button" value="提交" @click="update()">
    </form>
</div>
<script>
    //获取url上的请求参数
    function getParams() {
        //获取问号及问号后面的内容
        var url = window.location.search;
        var params = new Object();
        if (url.indexOf("?") != -1) {
            //截取问号后面的内容,再使用&分割多个属性
            var arr = url.substr(1).split("&");
            for (var i = 0; i < arr.length; i++) {
                //使用=分割为keyvalue
                var keyValue = arr[i].split("=");
                params[keyValue[0]] = keyValue[1];
            }
        }
        return params;
    }
    var vue = new Vue({
        el:"#app",
        data:{
            emp:{

            }
        },
        methods:{
            update:function () {
                $.post("http://localhost:9000/employees/update",$("#editFrom").serialize(),function (data) {
                    if (data.code == 200){
                        window.location.href="list.html"
                    }
                })
            }
        },
        mounted:function () {
            //获取URL后面的参数
            var map = getParams();
            var _this = this;
            //发送AJAX请求查询数据
            $.get("http://localhost:9000/employees/detail", {id:map.id}, function (data) {
                if (data.code == 200) {
                    _this.emp = data.data;
                } else {
                    alert(data.msg);
                }
            })
        }
    });

</script>
</body>
</html>